/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 *
 * https://www.renren.io
 *
 * 版权所有，侵权必究！
 */

package io.renren.modules.sys.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import io.renren.modules.sys.entity.SysDeptEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * 部门管理
 *
 * @author Mark sunlightcs@gmail.com
 */
@Mapper
public interface SysDeptDao extends BaseMapper<SysDeptEntity> {

    @ResultType(io.renren.modules.sys.entity.SysDeptEntity.class)
    @Select("select t1.*,(select t2.name from sys_dept t2 where t2.dept_id=t1.parent_id)parentName from sys_dept t1 where " +
            " t1.del_flag = 0 and dept_id=#{deptId}")
    @Results({
            @Result(column ="dept_id" ,property="userList",many = @Many(select = "io.renren.modules.sys.dao.SysUserDao.findByDeptId")),
    })
    SysDeptEntity queryWithUser(@Param("deptId") long deptId);

    List<SysDeptEntity> queryList(Map<String, Object> params);

    /**
     * 查询子部门ID列表
     * @param parentId  上级部门ID
     */
    List<Long> queryDetpIdList(Long parentId);

}
